package com.chen.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.chen.common.Result;

import com.chen.entity.Dict;
import com.chen.mapper.DictMapper;

import com.chen.service.DictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author chenchao
 * @date 2022/6/17 13:54
 * 数据字典
 */
@Service
@Transactional
public class DictServiceImpl extends ServiceImpl<DictMapper, Dict> implements DictService {

    @Resource
    private DictMapper dictMapper;

    @Autowired
    private RedisTemplate redisTemplate;




    public Result deleteDict(int id) {
        return Result.success(dictMapper.deleteById(id));
    }

    public IPage<Dict> selectPage(Integer pageNum, Integer pageSize, String name) {
//        创建Page1对象
        IPage<Dict> page = new Page<Dict>(pageSize, pageNum);
//QueryWrapper如果name不为空进行模糊查询
        QueryWrapper queryWrapper = new QueryWrapper();
        if (!"".equals(name)) {
            queryWrapper.like("name", name);
        }

        Page<Dict> selectPage = dictMapper.selectPage(new Page<>(pageNum, pageSize), queryWrapper);
        return selectPage;

    }

}
